﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows.Browser;
using SilverQuery;

namespace SilverQueryDemo.jqia.chapter5
{
	/// <summary>
	/// SilverQuery port of the collapsible.list.take.4 sample from Chapter 5 of jQuery In Action.
	/// </summary>
	public class CollapsibleList : SilverQueryComponent
	{
		public override void ready()
		{
			var parentNodes = @q("li:has(ul)");
			parentNodes.click(e => {
				if (e.relatedTarget == e.target) 
				{
					if (@q(e.relatedTarget).children().isMatch(":hidden")) 
					{
						@q(e.relatedTarget).css("list-style-image", "url(minus.gif)")
							.children()
							.slideDown("normal");
					}
					else
					{
						@q(e.relatedTarget)
							.css("list-style-image", "url(plus.gif)")
							.children()
							.slideUp("normal");
					}
				}
				return false;
			});

			//parentNodes.css("cursor", "pointer").css("list-style-image", "url(plus.gif)").children().hide();

			parentNodes.css(new map(){ 
			  {"cursor", "pointer"}, 
			  {"list-style-image", "url(plus.gif)"}
			}).children().hide();

			var leafNodes = @q("li:not(:has(ul))");
			leafNodes.css(new map(){
				{"cursor", "default"}, 
				{"list-style-image", "none"}
			});
		}
	}
}
